#include <iostream>
#include <stack>
#include <unordered_map>
#include <string>

bool isValidSequence(const std::string& sequence) {
    std::stack<char> stack;
    std::unordered_map<char, char> matchingBrackets = { {')', '('}, {']', '['}, {'}', '{'}, {'>', '<'} };
    for (char bracket : sequence) {
        if (bracket == '(' || bracket == '{' || bracket == '[' || bracket == '<') {
            stack.push(bracket);
        }
        else if (bracket == ')' || bracket == '}' || bracket == ']' || bracket == '>') {
            if (stack.empty() || stack.top() != matchingBrackets[bracket]) {
                return false;
            }
            stack.pop();
        }
        else {
            return false;
        }
    }
    return stack.empty();
}

int main() {
    std::string sequence;
    std::cout << "Введите скобочную последовательность: ";
    std::cin >> sequence;
    std::cout << std::boolalpha << isValidSequence(sequence) << std::endl;
    return 0;
}